home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / progem.lzh / apndx9.prf < prev    next >
Text File  |  1987-06-23  |  5KB  |  155 lines

  1. .!****************************************************************************
  2. .! 
  3. .! ANTIC PUBLISHING INC., COPYRIGHT 1985.  REPRINTED BY PERMISSION.
  4. .!
  5. .! ** Professional GEM ** by Tim Oren
  6. .!
  7. .! Proff File by ST enthusiasts at
  8. .! Case Western Reserve University
  9. .! Cleveland, Ohio
  10. .! uucp : decvax!cwruecmp!bammi
  11. .! csnet: bammi@case
  12. .! arpa : bammi%case@csnet-relay
  13. .! compuserve: 71515,155
  14. .!
  15. .!****************************************************************************
  16. .!
  17. .!            Begin Appendix 9
  18. .!
  19. .!***************************************************************************
  20. .!
  21. .!
  22. .AP IX Sample Code for Part XI
  23. /* >>>>>>>>>>>>>> Sample code for initializing User Objects <<<<<<<<<<<<<<<< */
  24.  
  25. GLOBAL    USERBLK extobjs[MAX_OBJS];    /* APPLBLK defined in OBDEFS.H    */
  26. GLOBAL    WORD    n_extobjs;        /* Set MAX_OBJS to total user   */
  27.                      /* objects in resource        */
  28.  
  29. VOID
  30. obj_init()                /* Scan whole resource for user   */
  31. {                    /* objects.  Uses map_tree()      */
  32.     LONG    tree, obspec;        /* from GEMCL5.C          */
  33.     WORD    itree, i, obj;
  34.     
  35.     n_extobjs = 0;            /* Replace TREE0 with your first  */
  36.     /* tree, TREEN with the last      */
  37.     for (itree = TREE0; itree <= TREEN; itree++)
  38.     {
  39.         rsrc_gaddr(R_TREE, itree, &tree);
  40.         map_tree(tree, ROOT, NIL, fix_obj);
  41.     }
  42. }
  43.  
  44. WORD
  45. fix_obj(tree, obj)            /* Code to check and fix up    */
  46. LONG    tree;            /* a user defined object    */
  47. WORD    obj;
  48. {
  49.     WORD    hibyte;
  50.     
  51.     hibyte = LWGET(OB_TYPE(obj)) & 0xff00;        /* check extended */
  52.     if (!hibyte)                    /* type - if none */
  53.         return (TRUE);                /* ignore object  */
  54.     extobjs[n_extobjs].ub_code = dr_code;        /* set drawcode   */
  55.     extobjs[n_extobjs].ub_parm = LLGET(OB_SPEC(obj)); /* copy obspec  */
  56.     LLSET(OB_SPEC(obj), ADDR(&extobjs[n_extobjs]));   /* point obspec */
  57.     LWSET(OB_TYPE(obj), G_USERDEF | hibyte);    /* to userblk &   */
  58.     n_extobjs++;                    /* patch type     */
  59.     return (TRUE);
  60. }
  61. .bp
  62. /* >>>>>>>>>>>>>>>>>>>> Sample User Object Drawing Code <<<<<<<<<<<<<<<<<<<< */
  63. /* >>>>>>>>>>>>>>>>>>>> Implements Rounded Box based    <<<<<<<<<<<<<<<<<<<< */
  64. /* >>>>>>>>>>>>>>>>>>>> on G_BOX type                <<<<<<<<<<<<<<<<<<<< */
  65.  
  66. WORD
  67. dr_code(pb)                /* Sample user object drawing   */
  68. PARMBLK    *pb;                /* code.  Caution: NOT portable */
  69. {                    /* to Intel small data models   */
  70.     LONG    tree, obspec;
  71.     WORD    slct, flip, type, ext_type, flags;
  72.     WORD    pxy[4];
  73.     WORD    bgc, interior, style, bdc, width, chc;
  74.     
  75.     tree = pb->pb_tree;
  76.     obspec = LLGET(pb->pb_parm);    /* original obspec from USERBLK  */
  77.     ext_type = LHIBT(LWGET(OB_TYPE(pb->pb_obj)));
  78.     slct = SELECTED & pb->pb_currstate;
  79.     flip = SELECTED & (pb->pb_currstate ^ pb->pb_prevstate);
  80.     set_clip(TRUE, &pb->pb_xc);    /* These two routines in GEMCL9.C */
  81.     grect_to_array(&pb->pb_x, pxy);    
  82.     
  83.     switch (ext_type) {
  84.         case 1:            /* Rounded box       */
  85.         /* Crack color word  */
  86.         get_colrwd(obspec, &bgc, &style, &interior,
  87.                &bdc, &width, &chc);
  88.         /* For select effect, use char color */
  89.         if (slct)    /* In place of background         */
  90.             bgc = chc;
  91.         /* Fill in background             */
  92.         rr_fill(MD_REPLACE, (width? 0: 1), bgc, interior, 
  93.             style, pxy);
  94.         /* Do perimeter if needed         */
  95.         /* rr_perim is in GEMCL9.C         */
  96.         if (width && !flip)
  97.         {
  98.             pxy[0] -= width; pxy[2] += width; 
  99.             rr_perim(MD_REPLACE, bdc, FIS_SOLID, width, pxy);
  100.         }
  101.         break;
  102.         default:        /* Add more types here            */
  103.         break;
  104.     }
  105.     return (0);
  106. }
  107.  
  108. VOID                /* Cracks the obspec color word    */
  109. get_colrwd(obspec, bgc, style, interior, bdc, width, chc)
  110. LONG    obspec;
  111. WORD    *bgc, *style, *interior, *bdc, *width, *chc, *chmode;
  112. {
  113.     WORD    colorwd;
  114.     
  115.     colorwd = LLOWD(obspec);
  116.     *bgc = colorwd & 0xf;
  117.     *style = (colorwd & 0x70) >> 4;
  118.     if ( !(*style) )
  119.         *interior = 0;
  120.     else if (*style == 7)
  121.         *interior = 1;
  122.     else if (colorwd & 0x80)    /* HACK: Uses character writing mode */
  123.         *interior = 3;        /* bit to select alternate interior  */
  124.     else                /* styles!                 */
  125.         *interior = 2;
  126.     *bdc = (colorwd & 0xf000) >> 12;
  127.     
  128.     *width = LHIWD(obspec) & 0xff;
  129.     if (*width > 127)
  130.         *width = 256 - *width;
  131.     
  132.     if (*width && !(*width & 0x1))        /* VDI only renders odd */
  133.         (*width)--;                /* widths!        */
  134.     
  135.     *chc = (colorwd & 0x0f00) >> 8;        /* used for select effect */
  136. }
  137.  
  138. VOID                /* Fill a rounded rectangle    */
  139. rr_fill(mode, perim, color, interior, style, pxy)
  140. WORD    mode, perim, color, style, interior, *pxy;
  141. {
  142.     vswr_mode(vdi_handle, mode);
  143.     vsf_color(vdi_handle, color);
  144.     vsf_style(vdi_handle, style);
  145.     vsf_interior(vdi_handle, interior);
  146.     vsf_perimeter(vdi_handle, perim);
  147.     v_rfbox(vdi_handle, pxy);
  148. }
  149. .!
  150. .!****************************************************************************
  151. .!
  152. .!            End Appendix 9
  153. .!
  154. .!****************************************************************************
  155.